<template>
	<view>
		<u-navbar title="设置"  back-icon-color='#ffffff' title-color="#ffffff" :is-back="true" :background="{backgroundImage: 'linear-gradient(45deg, #41d8dd, #5583ee)'} "></u-navbar>
		<input type="text" value="" v-model="nickName" placeholder="输入要修改的昵称" maxlength="6"/>
		<button type="primary" @tap="submit">修改昵称</button>
			<u-toast ref="uToast"/>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName:""
			};
		},
		methods:{
			submit(){
				this.$api.modify_user_info({
					nickName:this.nickName,
				}).then(res=>{
					console.log(res)
					if(res.data.code == 0){
						this.$refs.uToast.show({
							title:res.data.msg,
							type: 'success',
							position: "top"
						})
						let data = JSON.parse(uni.getStorageSync('userInfo'))
						data.nickName = this.nickName
						uni.setStorage('userInfo',data)
						uni.$emit('changNickName',data)
					}else{
						this.$refs.uToast.show({
							title:res.data.msg,
							type: 'error',
							position: "top"
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
input{
	padding: 20rpx;
	border: 1px solid;
	margin: 10rpx 15rpx;
}
button{
	width: 80%;
	font-size: 28rpx;
}

</style>
